package com.atguigu.bigdata.scala.mytest.chapter07

import scala.collection.mutable

object Test_Map {
  def main(args: Array[String]): Unit = {
    //不可变
    val map: Map[String, String] = Map(
      "a" -> "aa", "a" -> "aa", "b" -> "aa"
    )
    println(map)//Map(a -> aa, b -> aa)
    val str: String = map.mkString(",")
    println(str)//a -> aa,b -> aa

    println("==============================")
    //可变
    val map1: mutable.Map[String, Int] = mutable.Map(
      "a" -> 1, "a" -> 1, "B" -> 1, "c" -> 1
    )

    println(map1)//Map(a -> 1, c -> 1, B -> 1)

    map1.put("E",9)
    println(map1)

    map1.update("E",5)
    println(map1)

    println(map1.get("E"))

    map1.remove("E")
    println(map1)

    //获取key为"E"的value值,如果"E"这个key不存在返回指定的值9
    val a: Int = map1.getOrElse("E",9)
    println(a)//9





  }

}
